package com.zxn.rxbus.demo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.hwangjr.rxbus.RxBus
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.hwangjr.rxbus.thread.EventThread
import kotlinx.android.synthetic.main.activity_second.*

class SecondActivity : AppCompatActivity(), View.OnClickListener {
    companion object {
        @JvmStatic
        fun jumpTo() {
            //ARouter.getInstance().build(RouterConfig.MALLMAIN_ACTIVITY).navigation()
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)
        RxBus.get().register(this)

        btn_close.setOnClickListener(this)
        btn_third.setOnClickListener(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        RxBus.get().unregister(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.btn_close -> {
                RxBus.get().post(IRxBusTags.CLOSE_ALL, true)
                finish()
            }
            R.id.btn_third -> {
                startActivity(Intent(this, ThirdActivity::class.java))
            }
        }
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = [Tag(IRxBusTags.CLOSE_ALL),Tag(IRxBusTags.CLOSE_WAY1)])
    fun onEvent(s: Any) {
        Log.i(MainActivity.TAG, "onEvent: $s")
        finish()
    }

    @Subscribe(thread = EventThread.MAIN_THREAD)
    fun onEvent2(s: Any) {
        Log.i(MainActivity.TAG, "onEvent: $s")
        finish()
    }

}